
package Physics;
import java.util.Vector;

/*
import java.util.Iterator;
public class ForceRegistry {
	class ForceRegistration
	{
		public RigidBody object;
		public ForceGenerator fg;
	}
	private Vector<ForceRegistration> m_Registry;
	
	private m_Registry forceGenerators;
	
	public void add(RigidBody p_obj, ForceGenerator p_fg)
	{
		ForceRegistration r;
		r.object = p_obj;
		r.fg = p_fg;
		boolean found = false;
		Iterator i = m_Registry.iterator();
		i = forceGenerators.begin();
		while(i.hasNext())
		{
			if (i.object == object && i.fg == fg)
			{
				found = true;
				break;
			}
		}

		if (!found)
			forceGenerators.push_back(r);
	}
	public void remove(RigidBody p_obj)
	{
		Iterator i = m_Registry.iterator();
		i = forceGenerators.begin();
		while(i.hasNext())
		{
			if (i.object == object)
			{
				i = forceGenerators.erase(i);
			}
		}
	}
	void updateForces(float dt)
	{
		Iterator i = m_Registry.iterator();
		i = forceGenerators.begin();
		while(i.hasNext())
		{
			i.fg.updateForce(i.object, dt);
		}
	}
}*/


///////////////////////////////////////////
//ForceRegistry
///////////////////////////////////////////
//keeps track of all of the forces being applied to
//every object so we can iterate through them
///////////////////////////////////////////
class ForceRegistry
{
	public ForceRegistry()
	{
		m_forceGenerators = new Vector<ForceRegistration>();
	}
	
	protected class ForceRegistration
	{
		RigidBody m_object; // the object having a force applied to it
		ForceGenerator m_fg; // the force generator being applied to the object
	}
	
	Vector<ForceRegistration> m_forceGenerators;
	
	// STL vector object that keeps track of all force generators
	// and their respective objects
	
	// adds a FG to the list
	public void add(RigidBody object, ForceGenerator fg) 
	{
		ForceRegistration r = new ForceRegistration();
		r.m_object = object;
		r.m_fg = fg;
		boolean found = false;
	
		// check if the object/fg combo already exists
		for (int i = 0; i < m_forceGenerators.size(); ++i)
		{
			ForceRegistration fr = m_forceGenerators.get(i);
	
			if (fr.m_object == object && fr.m_fg == fg)
			{
				found = true;
				break;
			}
		}
	
		if (!found)
			m_forceGenerators.addElement(r);			
		}
		// removes a FG from the list
		public void remove(RigidBody object)
		{
			// check if the object/fg combo already exists
			for (int i = 0; i < m_forceGenerators.size(); ++i)
			{
				ForceRegistration fr = m_forceGenerators.get(i);
	
				if (fr.m_object == object)
					m_forceGenerators.remove(i);
			}			
		}
	// removes all FGs
	public void clear() 
	{
	
	}
	// tells all force generators to update their corresponding objects
	public void updateForces(double dt) 
	{
		for(int i = 0; i < m_forceGenerators.size(); ++i)
		{
			ForceRegistration fr = m_forceGenerators.get(i);
			fr.m_fg.updateForce(fr.m_object, dt);
		}
	}
}
